package jp.aist.gtrc.plus.admission.EDF.simulation;

public class Clock {
   private int now;

   public Clock() {
      this.now = 0;
   }

   public synchronized int getCurrentTime() {
      return this.now;
   }

   public synchronized void advanceTime(int time) {
      if (time < now) throw new RuntimeException("advanceTime() to the past (" + time + ") is prohibited.");
      now = time;
   }

   public synchronized void elapseTime(int elapsedTime) {
      if (elapsedTime < 0) throw new RuntimeException("elapsed time cannot be negative.");
      now = now + elapsedTime;
   }
  
   public synchronized void reset() {
      this.now = 0;
   }
}
